package com.gongpingjialoan.widget;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RadioGroup;

import com.gongpingjialoan.R;
import com.gongpingjialoan.activity.car.VipRecomendCarActivity;
import com.gongpingjialoan.widget.adapters.ArrayWheelAdapter;
import com.gongpingjialoan.widget.views.WheelView;

/**
 * Created by Administrator on 2016/3/22.
 */
public class RegisterVipFilterDialog extends Dialog {

    private Context mContext;

    private WheelView timeWheelView;

    private String[] times = {"00:00-06:00", "06:00-09:00", "09:00-12:00", "12:00-13:00", "13:00-18:00" , "18:00-24:00"};

    private ArrayWheelAdapter<String> timeWheelAdapter;

    private RadioGroup mRadioGroup;

    private Button mButton;

    private String type = "im";

    public RegisterVipFilterDialog(Context context) {
        super(context, R.style.dialogs);
        this.mContext = context;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.register_time_layout);
        timeWheelView = (WheelView) findViewById(R.id.time);
        mRadioGroup = (RadioGroup) findViewById(R.id.radiogroup);
        mButton = (Button) findViewById(R.id.sure_button);
        mRadioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                if (checkedId == R.id.radio1) {
                    type = "im";
                    timeWheelView.setVisibility(View.GONE);
                    timeWheelView.setEnabled(false);
                    timeWheelView.setShadowColor(0xAAFFFFFF, 0x65FFFFFF, 0xAAFFFFFF);
                    timeWheelView.setResourcesIfNecessary();
                    timeWheelView.invalidateWheel(false);
                } else if (checkedId == R.id.radio2) {
                    timeWheelView.setVisibility(View.VISIBLE);
                    type  = "od";
                    timeWheelView.setEnabled(true);
                    timeWheelView.setShadowColor(0xAAFFFFFF, 0xFFFFFF, 0xAAFFFFFF);
                    timeWheelView.setResourcesIfNecessary();
                    timeWheelView.invalidateWheel(false);
                }
            }
        });


        timeWheelView.setVisibleItems(3);
        timeWheelView.setCyclic(true);
        timeWheelAdapter = new ArrayWheelAdapter<String>(mContext, times);
        timeWheelAdapter.setItemResource(R.layout.time_tiem);
        timeWheelAdapter.setItemTextResource(R.id.text);
        timeWheelView.setViewAdapter(timeWheelAdapter);
        timeWheelView.setCurrentItem(2);
        timeWheelView.setShadowColor(0xAAFFFFFF, 0x65FFFFFF, 0xAAFFFFFF);
        timeWheelView.setEnabled(false);

        mButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                VipRecomendCarActivity vipRecomendCarActivity = (VipRecomendCarActivity) mContext;
                vipRecomendCarActivity.register(type , times[timeWheelView.getCurrentItem()]);
                dismiss();
            }
        });
    }
}
